<%--
 *  File:    BusiAreaEdit.jsp
 *  @Author: Langerwang 
 *  Date:    2001/12/14
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>

<%
  //init param
  Category cat = Category.getInstance("jsp.BusiAreaEdit");  
  String strModuleName = "OGM";
  String privilegeCode = "10109,L104";
  String contextPath = request.getContextPath();
%>

<%
  //get curuserinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  String strCurOrgName = (String)CurUserInfo.get("orgname");
  Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  if(nCurOrgId == null)
  {
    nCurOrgId = new Integer(-1234567);
  }

  //get area info
  String strAreaId = (String)request.getParameter("areaid");
  boolean bReadOnly = false;  
  boolean bIsEdit = false;
  if(strAreaId != null)
  {
    bIsEdit = true;
    bReadOnly = true;;
  }
  else
  {
    strAreaId = "";
  }
  String strParentAreaId = (String)request.getParameter("parentareaid"); 
  boolean bIsNewChild = true;
  if(strParentAreaId == null)
  {
    bIsNewChild = false;
  }
  boolean bIsNew = !bIsEdit && !bIsNewChild; 
  
%>
<%@ include file="/inc/Security.inc"%>
<%@ include file="/inc/PageDefault.inc"%>
<iframe name="reloadHandler" style="display:none" ></iframe>
<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="busiareaedit" />
<%@ include file="/inc/InitEdit.inc"%>
<%@ include file="/inc/CatchError.inc"%>
<%
  HashMap areaInfo = (HashMap)pageContext.getAttribute("areainfo");
  if(areaInfo == null)
  {
    areaInfo = new HashMap();
  }   
  
  Integer grade=(Integer)areaInfo.get("grade");
  Integer areatype=(Integer)areaInfo.get("areatype");
  if(grade == null){
	  grade=new Integer(0);
  }
  if(areatype == null){
	  areatype=new Integer(-1);
  }
  String strParentAreaName = "";
  if(bIsEdit)
  {
    strParentAreaName = (String)areaInfo.get("parentareaname");      
  }
  if(bIsNewChild)
  {
    strParentAreaName = (String)areaInfo.get("areaname");      
  }
  if(strParentAreaName == null)
  {
    strParentAreaName = new String("");
  }
  cat.debug("The areaInfo is :" + areaInfo);
  if(!bIsEdit)
  {
    pageContext.removeAttribute("areainfo");
  }
  String strIsBottom = "";
  strIsBottom = (String)areaInfo.get("isbottom");      
  String strIsCityRegion = "";
  Integer iscityregion=(Integer)areaInfo.get("iscityregion");
  if(iscityregion == null){
	  iscityregion=new Integer(0);
  }
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css"
	type="text/css">
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript">
function page_done()
{

   var areatype = document.busiareaeditform.areatype.value;
	if(areatype==null||areatype==" "){
		alert('<%=message.getMessageDesc("AREA_TYPE_IS_NULL")%>');
		return;
		}
  //alert(document.busiareaeditform.stdareatype.value);
 //if(!checkNull(document.busiareaeditform))return;  
  //if(!checkForm(document.busiareaeditform))return;  
  //page_checkareatype();

  if((document.busiareaeditform.strareaname.value==null)||(document.busiareaeditform.strareaname.value=="")||(document.busiareaeditform.strareaname.value==" ")){

  document.busiareaeditform.stdareatype.value=" "; }
  emptyToNull(document.busiareaeditform);  
  document.busiareaeditform.actionname.value = "done";
  isRunning = true;
  document.busiareaeditform.submit();
}

function page_showaArea(){
    if (document.busiareaeditform.areatype.value == 1) {
        if(document.busiareaeditform.stdareatype.length > 1){
         document.busiareaeditform.stdareatype.options[0].selected=true;
    	 document.busiareaeditform.stdareatype.command = "notnull" ;
    	}
        document.getElementById("area").style.display = "block";
    } else {
    	document.busiareaeditform.stdareatype.value = -1 ;
    	document.busiareaeditform.stdareatype.command = "" ;
    	document.getElementById("area").style.display = "none";
    }
} 

function ProGroup()
{
      if(popwindow!=null)
    popwindow.close();
    popwindow = window.open('AreaProFrm.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid='+document.busiareaeditform.areaid.value,'newwindow', 'height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');

}

function ProView()
{
     if(popwindow!=null)
    popwindow.close();
    popwindow = window.open('MapInfo.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid=<%=JspHelper.filterNull( areaInfo.get("areaid") )%>','newwindow', 'height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');

}
function getPosition(e) {
        var left = 0;
        var top = 0;
        while (e.offsetParent) {
            left += e.offsetLeft + (e.curentStyle? (parseInt(e.curentStyle.borderLeftWidth).NaN0()):0);
            top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
            e = e.offsetParent;
        }
        left += e.offsetLeft + (e.curentStyle ? (parseInt(e.curentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
        return {x:left, y:top};
}

function closeItemSelect(evt)
{
	var _obj = document.getElementById("summaryfrm");
	if(isHidden == "block"){
		isHidden = "none";
	}else{
		_obj.style.display = "none";
	}
	evt = evt || window.event;
        var _target = evt.target || evt.srcElement;
        if (!_target.getAttribute("Author") && _target != inputObj && _target != targetObj) {
            getObjById("Calendar").style.display = "none";
            getObjById("CalendarFrm").style.display = "none";
        }
}
function hiddenFrm(){
	document.getElementById("summaryfrm").style.display = "none";
}

function parentarea(e)
{ 
    isHidden = "block";
    var _target = getPosition(e);
    var _obj = document.getElementById("summaryfrm");
    _obj.style.left = _target.x;
    _obj.style.top = _target.y + e.clientHeight;
    _obj.style.height="300px";
    _obj.style.width="250px";
    _obj.style.zIndex = 5000;
    _obj.style.display = "block";
	var strUrl = "ProBusiAreaTree.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid=<%=JspHelper.filterNull( areaInfo.get("areaid") )%>";	
    if(popwindow!=null)
    popwindow.close();
    //var status = "height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
    //var url = "<%=contextPath %>/tdr/dataverify/SalesPopWindow.jsp?<%= OvalTools.randomURL() %>&regionid="+regionid+"&proviceofficecode="+proviceofficecode+"&businessareacode="+businessareacode;
    //popwindow = window.open('ProBusiAreaTree.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid=<%=JspHelper.filterNull( areaInfo.get("areaid") )%>','newwindow', 'height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
    document.summaryfrm.location.href = strUrl;
}
//document.onclick=closeItemSelect;  


function getcity()
{
      if(popwindow!=null)
    popwindow.close();
    popwindow = window.open("AreaCityMapFrm.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid="+document.busiareaeditform.areaid.value,"newwindow", "height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");

}
function getlowercity()
{
    if(popwindow!=null)
    popwindow.close();
    popwindow = window.open("TempBussinessareaInfo.jsp?<%= OvalTools.randomURL() %>&parentareaid="+document.busiareaeditform.areaid.value,"newwindow", "height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes");

}

function getcityforbottom()
{
     if(popwindow!=null)
    popwindow.close();
    popwindow = window.open("MapCityInfo.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&areaid=<%=JspHelper.filterNull( areaInfo.get("areaid") )%>&grade=<%=JspHelper.filterNull( areaInfo.get("grade") ) %>","newwindow", "height=500, width=700,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");

}
function page_getstdareaty(){
    var objdeptcode=eval("busiareaeditform.areatype");
	//var style = document.cform.style.value;
	if (objdeptcode==""){
	    return;
	}
	var  datahandler = new  DataHandler();
	//datahandler.add_params("style" , style, 'Integer');
	datahandler.add_params("areatype" , objdeptcode.value , "Integer");
	datahandler.getResultFromVector("stdaretypeinfo","areaname","stdareatype","document.busiareaeditform.stdareatype");
	datahandler.add_job("j_getstdareaty");
	datahandler.add_function("page_checkareatype()");
	datahandler.runDataHandler();
   
  }
  function page_checkareatype() {

  if (document.busiareaeditform.areatype.value == null||document.busiareaeditform.areatype.value == ""||document.busiareaeditform.areatype.value == " ") {

    	document.busiareaeditform.stdareatype.value = " " ;
    	document.busiareaeditform.stdareatype.command = "" ;
    	//document.getElementById("area").style.display = "none";
    } else {
    // if(document.busiareaeditform.stdareatype.length > 1){

         //document.busiareaeditform.stdareatype.options[0].selected=true;
    	 document.busiareaeditform.stdareatype.command = "notnull" ;
    	//}
        document.getElementById("area").style.display = "block";
        
    }
    
  }
  
  
  function page_popBusinessarea()
  {
	if(popwindow!=null)
    popwindow.close();
    popwindow = window.open("zylstdbusinessareapop.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>","newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
  }

  function setContact(id,type,name){
	document.busiareaeditform.stdareatype.value=id;
	document.busiareaeditform.strareaname.value=name;
  	//alert(document.busiareaeditform.stdareatype.value);
  }
</script>
</head>
<iframe name="summaryfrm" scrolling="no" frameborder="0"
	style="position:absolute; top:0px; left:0px; display:none;border:#909eff 1px solid;"></iframe>
<body>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
	<custom:hidden property="areaid" />
	<tr>
		<td>
		<table width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td colspan="2" class="summary_top"></td>
			</tr>
			<tr>
				<td colspan="2"><img
					src="../../images/<%= strLanguageCode %>/quote.gif" width="16"
					height="11"> <%= label.getLabelName("L_NEBusinessArea") + label.getLabelName("L_Colon") %></td>
			</tr>
		</table>
		<table width="100%" border="1" cellpadding="0"
			bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0"
			align="center">
			<form name="busiareaeditform" method="post" action="../../Dispatcher"
				target="_parent"><input type="hidden" name="pagename"
				value="busiareaedit"> <input type="hidden" name="actionname"> <%if(bIsEdit){%>
			<input type="hidden" name="areaid"
				value="<%=JspHelper.filterNull( areaInfo.get("areaid") )%>"> <%}%> <%if(bIsNewChild){%>
			<input type="hidden" name="parentareaid"
				value="<%=JspHelper.filterNull( strParentAreaId )%>"> <input
				type="hidden" name="grade"
				value="<%=JspHelper.filterNull( request.getParameter("grade") )%>">
			<input type="hidden" name="isbottom"
				value="<%=JspHelper.filterNull( new String("Y") )%>"> <%}%> <%if(bIsNew){%>
			<input type="hidden" name="grade"
				value="<%=JspHelper.filterNull( new Integer(1) )%>"> <input
				type="hidden" name="isbottom"
				value="<%=JspHelper.filterNull( new String("Y") )%>"> <%}%> <input
				type="hidden" name="orgid"
				value="<%=JspHelper.filterNull( nCurOrgId )%>"> <%if(bIsEdit){
        	//String strIsBottom=(String)areaInfo.get("isbottom");
        	if(grade.intValue() == 2){
            %>
			<tr>
				<td class="td-text"><%= label.getLabelName("L_ProductGroup") + label.getLabelName("L_Colon") %></td>
				<td><a onclick="ProGroup();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a></td>
			</tr>
			<% }else{%>
			<tr>
				<td class="td-text"><%= label.getLabelName("L_ProductGroup") + label.getLabelName("L_Colon") %></td>
				<td><a onclick="ProView();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a></td>
			</tr>
			<%} 
       	}else{ %>
			<tr>
				<td class="td-text"><%= label.getLabelName("L_ProductGroup") + label.getLabelName("L_Colon") %></td>
				<td>&nbsp;</td>
			</tr>
			<%} %>

<tr>
<td class="need"><%= label.getLabelName("L_AreaCode") + label.getLabelName("L_Colon") %></td>
<td><custom:text name="areainfo" property="areacode" size="34" label="L_AreaCode" command="notnull" readonly="<%= bIsEdit %>"/></td>
</tr>
<tr>
<td class="need"><%= label.getLabelName("L_AreaName") + label.getLabelName("L_Colon") %></td>
<td><custom:text name="areainfo" property="areaname" size="34" label="L_AreaName" command="notnull" /></td>
</tr>
			<tr>
				<td class="td-text" ><%= label.getLabelName("L_Department") + label.getLabelName("L_Colon") %></td>
				<td><custom:write name="areainfo" property="deptname" nbsp="true" /></td>
			</tr>
			<tr>
				<!--<td class="td-text" width="140"><%= label.getLabelName("L_WhetherRetail") + label.getLabelName("L_Colon") %></td>
				<td>&nbsp;<custom:selectdic name="areainfo" property="isretail"
					dictType="YesOrNo" valueCriteria="1,2" onchange="page_showaArea()"
					defaultValue="----" /></td>
			    -->
				<td class="td-text" width="140"><%= label.getLabelName("L_IsKeynote") + label.getLabelName("L_Colon") %></td>
				<td>&nbsp;<custom:selectdic name="areainfo" property="isretail"
					dictType="YesOrNo" valueCriteria="1,2" 
					defaultValue="----" />
			</tr>
			<!-- 
			<tr id="area" style="display:none">
				<td class="need" width="140"><%= label.getLabelName("L_SmallArea") + label.getLabelName("L_Colon") %></td>
				<td><custom:selectdic name="areainfo" property="smallarea"
					dictType="SmallArea" defaultValue="----" label="L_SmallArea" /></td>
			</tr>
			-->
			<tr>
				<td class="td-text" width="140"><%= label.getLabelName("L_BusinessAreaDesc") + label.getLabelName("L_Colon") %></td>
				<td><custom:write name="areainfo" property="areadesc" nbsp="true" /></td>
			</tr>
			<tr>
				<td class="td-text" height="13" width="140"><%= label.getLabelName("L_ParentArea") + label.getLabelName("L_Colon") %></td>
				<td><%=JspHelper.filterNull( strParentAreaName )%> <!--<a onclick="javascript:javascript:parentarea(this);"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a>
				 &nbsp;<%=JspHelper.filterNull( strParentAreaName )%>--></td>
			</tr>
			<!--<tr>
				<td class="td-text" height="13" width="140"><%= label.getLabelName("L_IsKeynote") + label.getLabelName("L_Colon") %></td>
				<td>&nbsp; <custom:checkbox property="preflag1" /></td>
			</tr>
			
			<!--
			<tr>
				<td class="td-text" width="140"><%= label.getLabelName("L_City_Region") + label.getLabelName("L_Colon") %></td>
				<td>&nbsp;<custom:selectdic name="areainfo" property="iscityregion"
					dictType="YesOrNo" valueCriteria="1,2" defaultValue="----" /></td>
			</tr>
			-->
			<tr>
				<td class="td-text" height="13" width="140"><font color="red"><%= label.getLabelName("L_AreaType") + label.getLabelName("L_Colon") %></font></td>
				<td>&nbsp;<custom:selectdic dictType="ZYLAreaType" name="areainfo" property="areatype" 
					style="border:0" defaultValue="------" defaultValueCost=" " onchange="page_getstdareaty()" style="width:100px"
					/></td>
			</tr>
			<tr id="area" >
				<td class="td-text" width="140"><%= label.getLabelName("L_Provicetdr") + label.getLabelName("L_Colon") %></td>
				<td>
				    <!--<custom:selectdic name="areainfo" property="stdareatype"
					dictType="ZYLAreaType" label="L_Actua_Business" />
					-->
					
					<custom:hidden property="stdareatype" name="areainfo" />
		           	<custom:text property="strareaname" name="areainfo"/>
		           	<a onclick="page_popBusinessarea();"><custom:button type="3" value="*"/></a>
				</td>
			</tr>
			<%if(bIsEdit){
        	//String strIsBottom=(String)areaInfo.get("isbottom");
        	if(strIsBottom.equals("Y")){
            %>
			<tr>
				<td class="td-text" width="130"><%= label.getLabelName("L_CoveringCity") + label.getLabelName("L_Colon") %></td>
				<td><a onclick="getcity();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a></td>
			</tr>
			<tr>
				<td class="td-text" width="140"><%= label.getLabelName("L_Junior_City") + label.getLabelName("L_Colon") %></td>
				<td><a onclick="getlowercity();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a>
			    </td>
			</tr>
			<% }else{%>
			<tr>
				<td class="td-text" width="130"><%= label.getLabelName("L_CoveringCity") + label.getLabelName("L_Colon") %></td>
				<td><a onclick="getcityforbottom();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a></td>
			</tr>
			<%} 
       	}else{ %>
       	   <tr>
		       <td class="td-text" height="13" ><%= label.getLabelName("L_CoveringCity") + label.getLabelName("L_Colon") %></td>
			   <td>&nbsp;</td>
		   </tr>
			<%} %>
			</form>
		</table>
		</td>
	</tr>
	<tr>
		<td class="summary_top"></td>
	</tr>
	<tr>
		<td class="td_center"><a onclick="page_done()"><custom:button type="1"
			label="L_Finish" imgsrc="finish.gif" border="0" style="width:60" /></a></td>
	</tr>
</table>
</body>
<script type="text/javascript">
/*var isHidden;
if(document.busiareaeditform.areatype.value != -1){
	document.getElementById("area").style.display = "block";
}*/
</script>
</html>


